<?#//v.3.0.0
#///////////////////////////////////////////////////////
#//  COPYRIGHT 2004 Phpauction.org ALL RIGHTS RESERVED//
#///////////////////////////////////////////////////////

require('../includes/config.inc.php');
include "loggedin.inc.php";


#//Default for error message (blank)
$ERR = "&nbsp;";


if(isset($_POST[InsertButton]) && strlen($_POST[cat_name]) > 0 && phpa_securepost($_POST))
{
	$query = "insert into PHPAUCTIONXL_faqscategories values(NULL,
		'".addslashes($_POST[cat_name][$SETTINGS['defaultlanguage']])."')";
	$res = @mysql_query($query);
	if(!$res)
	{
		print "Error: $query<BR>".mysql_error();
		exit;
	}
	$id = mysql_insert_id();
	reset($LANGUAGES);
	while(list($k,$v) = each($LANGUAGES)){
		@mysql_query("INSERT INTO PHPAUCTIONXL_faqscat_translated VALUES($id,'$k','".addslashes($_POST['cat_name'][$k])."')");
	}
}

#// Delete categories
if(is_array($_POST[delete]) && phpa_securepost($_POST))
{
	while(list($k,$v) = each($_POST[delete]))
	{
		$query = "delete from PHPAUCTIONXL_faqscategories where id=$v";
		$r = @mysql_query($query);
		if(!$r)
		{
			print "Error: $query<BR>".mysql_error();
			exit;
		}
		@mysql_query("DELETE FROM PHPAUCTIONXL_faqscat_translated WHERE id=$v");
	}
}


#// Get data from the database
$query = "select * from PHPAUCTIONXL_faqscategories order by category";
$res__ = @mysql_query($query);
if(!$res__)
{
	print "Error: $query<BR>".mysql_error();
	exit;
}

?>
<HTML>
<HEAD>
<link rel='stylesheet' type='text/css' href='style.css' />
<link href="css/main.css" rel="stylesheet" type="text/css">
</HEAD>
<bodyleftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<FORM NAME="categories" METHOD="post" ACTION="<?=basename($_SERVER['PHP_SELF'])?>">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="titulo">
        <tr> 
          <td class="icono"><img src="images/content_icon2.gif" width="28" height="27" ></td>
          <td class="breadcrumbs"><p><span><?=$MSG_25_0018?></span>&nbsp;&gt;&gt;&nbsp;<?=$MSG_5230?></p></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td align="center" valign="middle">&nbsp;</td>
  </tr>
    <tr> 
    <td align="center" valign="middle">
	<TABLE WIDTH="95%" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER">
		<TR align=center>
			<TD BGCOLOR="#ffffff">&nbsp;</TD>
		</TR>
		<TR>
			<TD>
				<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER" class="base" style="border:1px solid #ccc;">
					<TR BGCOLOR="#0083D7">
						<TD COLSPAN="3" class=title>
						<p>		<?=$MSG_5230?></p>
						</TD>
					</TR>
					<TR BGCOLOR="#FFFFFF">
						<TD COLSPAN="3" class="error">
							<p><?=$ERR?></p>
							</TD>
					</TR>
					<TR BGCOLOR="#EEEEEE">
						<TD COLSPAN="3">
						<p><?=$MSG_5234?></p>
						</TD>
					</TR>
					<TR BGCOLOR="#FFFFFF">
						<TD COLSPAN="3">
							<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="1">
								<TR>
									<TD WIDTH="21%"><p class="blue"><?=$MSG_165?></p></TD>
									<TD WIDTH="79%">
										<IMG SRC="../includes/flags/<?=$SETTINGS['defaultlanguage']?>.gif">&nbsp;<INPUT TYPE="text" NAME="cat_name[<?=$SETTINGS['defaultlanguage']?>]" SIZE="25" MAXLENGTH="200">
										<?
											reset($LANGUAGES);
											while(list($k,$v) = each($LANGUAGES)){
												if($k!=$SETTINGS['defaultlanguage']) print "<BR><IMG SRC=../includes/flags/".$k.".gif>&nbsp;<INPUT TYPE=text NAME=cat_name[$k] SIZE=25 MAXLENGTH=200>";
											}
										?>
									</TD>
								</TR>
								<TR>
									<TD WIDTH="21%">
										<p><INPUT TYPE="hidden" NAME="action" VALUE="insert"></p>
									</TD>
									<TD WIDTH="79%">
										<INPUT TYPE="submit" NAME="InsertButton" VALUE="INSERT CATEGORY" class="action">
									</TD>
								</TR>
							</TABLE>
						</TD>
					</TR>
					<TR BGCOLOR="#FFFFFF">
						<TD COLSPAN="3"><p class="blue"><?=$MSG_5235?></p></TD>
					</TR>
					<TR BGCOLOR="#eeeeee">
						<TD WIDTH="14%"><p><?=$MSG_5237?></p></TD>
						<TD WIDTH="72%"><?=$MSG_5236?></TD>
						<TD WIDTH="14%" ALIGN=CENTER>
							<INPUT TYPE="submit" NAME="Submit" VALUE="Delete" class="action">
							<INPUT TYPE="hidden" NAME="security" VALUE="<?php echo $_SESSION['security'];?>" />
						</TD>
					</TR>
					<?
					while($row = mysql_fetch_array($res__))
					{
						$row[category]=stripslashes($row[category]);
						#// Are there FAQs for this category?
						$query = "select id from PHPAUCTIONXL_faqs where category=$row[id]";
						$re = @mysql_query($query);
						if(mysql_num_rows($re) > 0)
						{
							$HAVEFAQS = TRUE;
						}
						else
						{
							$HAVEFAQS = FALSE;
						}
						
					?>
					<TR BGCOLOR="#eeeeee">
						<TD WIDTH="7%" BGCOLOR="#FFFFFF">
							
							<p><?=$row[id]?></p>
							
						</TD>
						<TD WIDTH="79%" BGCOLOR="#FFFFFF">
							
							<A HREF=editfaqscategory.php?id=<?=$row[id]?>>
							<?=$row[category]?>
							</A>
							
							</TD>
						<TD WIDTH="14%" BGCOLOR="#FFFFFF" ALIGN=CENTER>
						<?
						if(!$HAVEFAQS)
						{
						?>
							<INPUT TYPE="checkbox" NAME="delete[<?=$row[id]?>]" VALUE="<?=$row[id]?>">
						<?
						}
						?>
						</TD>
					</TR>
					<?
					}
					?>
					<TR BGCOLOR="#eeeeee">
						<TD WIDTH="7%" BGCOLOR="#FFFFFF">&nbsp;</TD>
						<TD WIDTH="79%" BGCOLOR="#FFFFFF">&nbsp;</TD>
						<TD WIDTH="14%" BGCOLOR="#FFFFFF" ALIGN=CENTER>
							<INPUT TYPE="submit" NAME="Submit" VALUE="Delete" class="action">
							<INPUT TYPE="hidden" NAME="security" VALUE="<?php echo $_SESSION['security'];?>" />
						</TD>
					</TR>
				</TABLE>
			</TD>
		</TR>
	</TABLE>
</TD>
</TR>
</TABLE>
</FOrM>
</BODY>
</HTML>
